package com.lanou.fooddemo.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.lanou.fooddemo.util.CommonUtil;

import java.util.List;

/**
 * Created by LiuYan on 2015/8/6.
 * 主页TabHost内容填充ViewPager的内容Adapter
 */
public class MainTabFragmentAdapter extends FragmentPagerAdapter {
    /**
     * Fragment的List变量
     */
    private List<Fragment> fragmentList;
    public MainTabFragmentAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        fragmentList = fragments;
    }

    /**
     * 根据位置取得Fragment
     * @param i 位置
     * @return 该位置的Fragment
     */
    @Override
    public Fragment getItem(int i) {
        if (CommonUtil.isListNotNull(fragmentList)) {
            return fragmentList.get(i);
        }
        return null;
    }

    /**
     * 返回Fragment总数量
     * @return Fragment总数量
     */
    @Override
    public int getCount() {
        if (CommonUtil.isListNotNull(fragmentList)) {
            return fragmentList.size();
        }
        return 0;
    }
}
